function validateMatch()
{

	
	//clearing divs
	clearMatchDivs();
	
	//retrieving fields
	var tournament     	  = document.getElementById('tournament').value;	
	var date         	  = document.getElementById('date').value;
	var time        	  = document.getElementById('time').value;
	var placeOfMatch      = document.getElementById('place_of_match').value; 
	var day   			  = $('input[type=radio][id=type-day]:checked').val();
	var dayNight          = $('input[type=radio][id=type-dayNight]:checked').val();
	var counter      = 0;
	
	//check for tournament
	if(tournament == 0)
	{
		document.getElementById('divTournament').innerHTML = "<span class='error'>Please Select Tournament</span>";
		counter=counter+1;
	}
	else
	{
		document.getElementById('divFirstTeam').innerHTML = "";
		document.getElementById('divSecondTeam').innerHTML = "";
		var firstTeam         = document.getElementById('first_team').value;
		var secondTeam        = document.getElementById('second_team').value;	
		//check for first team
		if(firstTeam == 0)
		{
	
			document.getElementById('divFirstTeam').innerHTML = "<span class='error'>Please Enter First Team</span>";
			counter=counter+1;
		
		}
		//check for second team
		if(secondTeam == 0)
		{
			document.getElementById('divSecondTeam').innerHTML = "<span class='error'>Please Enter Second Team</span>";
			counter=counter+1;
		}
		if(firstTeam == secondTeam)
		{
			document.getElementById('divSecondTeam').innerHTML = "<span class='error'>Both teams should not be same</span>";
			counter=counter+1;
		}
	}
	
	//check for Date
	if(date == "")
	{
		document.getElementById('divDate').innerHTML = "<span class='error'>Please Enter Date</span>";
		counter=counter+1;
	}
	//check for Date
	if(placeOfMatch == "")
	{
		document.getElementById('divPlaceOfMatch').innerHTML = "<span class='error'>Please Enter Place of Match</span>";
		counter=counter+1;
	}
	if(!day && !dayNight   )
	{
		document.getElementById('divDayNight').innerHTML ="<font color='red'>Please check whether it is day/night match</font>";
		counter=counter+1;
		
	}
	//check for Date
	if(time == "")
	{
		document.getElementById('divTime').innerHTML = "<span class='error'>Please Enter Time</span>";
		counter=counter+1;
	}
	if(counter > 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function clearMatchDivs()
{
	
	document.getElementById('divTournament').innerHTML = "";
	document.getElementById('divDayNight').innerHTML = "";
	document.getElementById('divPlaceOfMatch').innerHTML ="";
	document.getElementById('divDate').innerHTML = "";
	document.getElementById('divTime').innerHTML = "";
	
}


function displayTeams(tournamentID)
{
	
	var dataString = "tournamentID="+tournamentID;
	$.ajax({
		type:"GET",
		url:displayTeamUrl,
		data:dataString,
		success:function(html)
		{
			document.getElementById('divTeam').innerHTML = html;
		}
		
		
	});
}
function displayPlayers(teamID,matchID)
{
	
	var dataString = "teamID="+teamID+"&matchID="+matchID;
	$.ajax({
		type:"GET",
		url:displayPlayerUrl,
		data:dataString,
		success:function(html)
		{
			document.getElementById('divPlayer').innerHTML = html;
		}
		
		
	});
}
function disablePlayer(chk,i,type)
{
	

	if(type == "first team")
	{
		var playerId     = document.getElementById('playerId'+i);
		var battingPts 	 = document.getElementById('battingPts'+i);
		var bowlingPts 	 = document.getElementById('bowlingPts'+i);
		var notout   	 = document.getElementById('notout'+i);
		var catchPts   	 = document.getElementById('catch'+i);
		var fielding   	 = document.getElementById('fielding'+i);
		
		
	}
	else
	{
		var playerId     = document.getElementById('secondPlayerId'+i);
		var battingPts 	 = document.getElementById('secondBattingPts'+i);
		var bowlingPts 	 = document.getElementById('secondBowlingPts'+i);
		var notout   	 = document.getElementById('secondNotout'+i);
		var catchPts   	 = document.getElementById('secondCatch'+i);
		var fielding   	 = document.getElementById('secondFielding'+i);
		
	}
	if(chk.checked  == true)
	{
		playerId.disabled 		    = false;
		battingPts.disabled 		= false;
		bowlingPts.disabled 		= false;
		catchPts.disabled 			= false;
		notout.disabled             = false;
		fielding.disabled 			= false;
						
	}
	else
	{
		playerId.disabled 		    = true;
		battingPts.disabled 		= true;
		bowlingPts.disabled 		= true;
		catchPts.disabled 			= true;
		notout.disabled             = true;
		fielding.disabled 			= true;
	}
	
	
}

function validateResult()
{
	var team = document.getElementById('team').value;
	var counter = 0;
	if(team == "")
	{
		document.getElementById('teamDiv').innerHTML =  "<span class='error'>Please Select Team</span>";
		counter = counter + 1;
	}
	
	if(counter > 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}